/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditChapter.java
 *
 * Created on Aug 13, 2011, 7:44:38 PM
 */
package azure;

import org.jdesktop.application.Action;

/**
 *
 * @author Gargravarr
 */
public class EditChapter extends javax.swing.JFrame
{
    public Chapter chapter;
    /** Creates new form EditChapter */
    public EditChapter()
    {
	initComponents();
    }
    
    public void setContent(Chapter c)
    {
	this.chapter = c;
	this.setTitle(c.toString());
	this.jsChapterNo.setValue(c.chapterNo);
	this.jsChapterVersion.setValue(c.chapterVersion);
	this.jepDescriptionEditor.setText(c.chapterDescription);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jsChapterVersion = new javax.swing.JSpinner();
        jlChapterVersion = new javax.swing.JLabel();
        jspEditorPane = new javax.swing.JScrollPane();
        jepDescriptionEditor = new javax.swing.JEditorPane();
        jlChapterDescription = new javax.swing.JLabel();
        jbCancel = new javax.swing.JButton();
        jbSave = new javax.swing.JButton();
        jlChapterNo = new javax.swing.JLabel();
        jsChapterNo = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jsChapterVersion.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));
        jsChapterVersion.setName("jsChapterVersion"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(azure.Main.class).getContext().getResourceMap(EditChapter.class);
        jlChapterVersion.setText(resourceMap.getString("jlChapterVersion.text")); // NOI18N
        jlChapterVersion.setName("jlChapterVersion"); // NOI18N

        jspEditorPane.setName("jspEditorPane"); // NOI18N

        jepDescriptionEditor.setName("jepDescriptionEditor"); // NOI18N
        jspEditorPane.setViewportView(jepDescriptionEditor);

        jlChapterDescription.setText(resourceMap.getString("jlChapterDescription.text")); // NOI18N
        jlChapterDescription.setName("jlChapterDescription"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(azure.Main.class).getContext().getActionMap(EditChapter.class, this);
        jbCancel.setAction(actionMap.get("closeForm")); // NOI18N
        jbCancel.setText(resourceMap.getString("jbCancel.text")); // NOI18N
        jbCancel.setName("jbCancel"); // NOI18N

        jbSave.setAction(actionMap.get("saveChapterChanges")); // NOI18N
        jbSave.setText(resourceMap.getString("jbSave.text")); // NOI18N
        jbSave.setName("jbSave"); // NOI18N

        jlChapterNo.setText(resourceMap.getString("jlChapterNo.text")); // NOI18N
        jlChapterNo.setName("jlChapterNo"); // NOI18N

        jsChapterNo.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(0), null, Integer.valueOf(1)));
        jsChapterNo.setName("jsChapterNo"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jspEditorPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jbSave)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jbCancel)
                        .add(26, 26, 26))
                    .add(layout.createSequentialGroup()
                        .add(jlChapterVersion)
                        .add(18, 18, 18)
                        .add(jsChapterVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 58, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jlChapterDescription)
                    .add(layout.createSequentialGroup()
                        .add(jlChapterNo)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jsChapterNo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 58, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jlChapterNo)
                    .add(jsChapterNo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jlChapterVersion))
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jsChapterVersion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18)
                .add(jlChapterDescription)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jspEditorPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 169, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jbSave)
                    .add(jbCancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
	/* Set the Nimbus look and feel */
	//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
	 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
	 */
	try
	{
	    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
	    {
		if ("Nimbus".equals(info.getName()))
		{
		    javax.swing.UIManager.setLookAndFeel(info.getClassName());
		    break;
		}
	    }
	}
	catch (ClassNotFoundException ex)
	{
	    java.util.logging.Logger.getLogger(EditChapter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	catch (InstantiationException ex)
	{
	    java.util.logging.Logger.getLogger(EditChapter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	catch (IllegalAccessException ex)
	{
	    java.util.logging.Logger.getLogger(EditChapter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	catch (javax.swing.UnsupportedLookAndFeelException ex)
	{
	    java.util.logging.Logger.getLogger(EditChapter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
	}
	//</editor-fold>

	/* Create and display the form */
	java.awt.EventQueue.invokeLater(new Runnable()
	{

	    public void run()
	    {
		new EditChapter().setVisible(true);
	    }
	});
    }

    @Action
    public void closeForm()
    {
	this.dispose();
    }

    @Action
    public void saveChapterChanges()
    {
	chapter.isModified = true;
	chapter.chapterNo = Integer.parseInt(jsChapterNo.getValue().toString());
	chapter.chapterVersion = Integer.parseInt(jsChapterVersion.getValue().toString());
	chapter.chapterDescription = jepDescriptionEditor.getText();
	closeForm();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jbCancel;
    private javax.swing.JButton jbSave;
    private javax.swing.JEditorPane jepDescriptionEditor;
    private javax.swing.JLabel jlChapterDescription;
    private javax.swing.JLabel jlChapterNo;
    private javax.swing.JLabel jlChapterVersion;
    private javax.swing.JSpinner jsChapterNo;
    private javax.swing.JSpinner jsChapterVersion;
    private javax.swing.JScrollPane jspEditorPane;
    // End of variables declaration//GEN-END:variables
}
